<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="typeList">
      <el-table-column label="用工部门" align="center" prop="wspDeptPost.deptName" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="用工岗位" align="center" prop="wspDeptPost.postName" :show-overflow-tooltip="true" />
      <el-table-column label="院系专业" align="center" prop="dm" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="学生姓名" align="center" prop="studentName"></el-table-column>
      <el-table-column label="注册号" align="center" prop="regCode"></el-table-column>
      <el-table-column label="用工薪酬" align="center" prop="wspDeptPost.postComp">
        <template slot-scope="scope">
                    {{ scope.row.wspDeptPost.postComp}}元/小时
                </template>
      </el-table-column>
      <el-table-column label="用工时长" align="center" prop="wspDeptPost.workHours">
        <template slot-scope="scope">
                    {{ scope.row.wspDeptPost.workHours}}小时
                </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="apprStatus">
        <template slot-scope="scope">
              <dict-tag :options="dict.type.wsp_appr_status" :value="scope.row.apprStatus"></dict-tag>
            </template>
      </el-table-column>
      <el-table-column label="审核原因" align="center" prop="apprCause" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="申请时间" align="center" prop="applyTime" :show-overflow-tooltip="true"></el-table-column>
   
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleExamine(scope.row)" v-hasPermi="['wsp:postemp:appr']" v-if="scope.row.apprStatus == 'D' ? true : false">审核</el-button>
          <el-button size="mini" type="text" @click="handleDelete(scope.row)"  v-hasPermi="['wsp:postemp:remove']">删除</el-button>
          <el-button size="mini" type="text" @click="handleDetail(scope.row)"  v-hasPermi="['wsp:postemp:query']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
       <!-- 审核对话框 -->
       <el-dialog title="审核" :visible.sync="examine" @close="cancel" width="30%" append-to-body destroy-on-close>
            <el-form ref="form" :model="form" :rules="rules" label-width="90px">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="审核结果:" prop="apprType">
                            <el-radio-group v-model="form.apprType">
                                <el-radio label="Y">通过</el-radio>
                                <el-radio label="N">不通过</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="不通过原因:" prop="apprCause" v-if="form.apprType == 'Y' ? false : true">
                            <el-input v-model="form.apprCause" placeholder="请输入审核失败原因" maxlength="20"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <detail ref="detailRef" :treeData="getTeacherList" @updateList="getlistAppr"></detail>
  </div>
</template>
  
<script>
import detail from './detail.vue'
import {getSelector,delConsbasic} from "@/api/psychological/basic"
import { postempList,postempAppr,postempDel } from '@/api/worStudy/postManagement'

export default {
  name: "Dict",
  dicts: ['wsp_appr_status'],
  components: {
    detail
  },

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      names: [],
      getTeacherList:[],
      timeVisibke: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      // 总条数
      total: 0,
      // 字典表格数据
      typeList: [],
      examine:false,
      form: {
        apprType: 'Y'
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
      },
      rules: {
        apprType: [
                    { required: true, message: "请选择审核结果", trigger: "change" }
                ],
                apprCause: [
                    { required: true, message: "请输入不通过原因", trigger: "blur" },
                    { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
                ],
            }
    };
  },
  created() {
    getSelector().then(res => {
      this.getTeacherList = res.data
    })
  },
  methods: {
    /** 查询字典类型列表 */
    getList(data) {
      this.queryParams = data
      this.loading = true
      if(data.page || data.limit) {
                data.pageNum = data.page 
                data.pageSize = data.limit 
                this.queryParams.pageNum = data.page 
                this.queryParams.pageSize = data.limit 
            }
      postempList(data).then(response => {
        this.typeList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    cancel() {
      this.examine = false
      this.form = {}
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm('是否确认删除学生"' + row.studentName +'"的在岗数据项？')
        .then(function() {
          return postempDel(row.wpeId);
        })
        .then(() => {
          this.getList(this.queryParams);
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});

    },
    handleExamine(row) {
      this.examine = true
      this.form =  JSON.parse(JSON.stringify(row))
    },
    // 详情
    handleDetail(row) {
      this.$refs.detailRef.open(JSON.parse(JSON.stringify(row)), 'detailRef')
    },
    getlistAppr() {
      this.getlist(this.queryParams)
    },
     // 审核提交按钮
     submitForm() {
            this.$refs["form"].validate(valid => {
                postempAppr(this.form).then(response => {
                  this.getList(this.queryParams)
                    this.$modal.msgSuccess("审核成功");
                    this.examine = false;

                });

            });
        },
  }
};
</script>
<style scoped>
::v-deep .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}

.avatar {
  width: 150px;
  height: 150px;
  display: block;
  border: 1px dashed red;
}

.uploaderText {
  display: flex;
}

.text {
  margin-left: 15px;
  line-height: 35px;
  color: #9A9A9A;
}
.container {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}
 
.left {
  width: 30%
}
.right {
  width: 65%
  
}
</style>